package com.yanfan.zutai.controller;


import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.zutai.domain.BTexteditor;
import com.yanfan.zutai.service.IBTexteditorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文本编辑器生成Controller
 *
 * @author ruoyi
 * @date 2020-11-16
 */
@RestController
@RequestMapping("/zutai/texteditor")
public class BTexteditorController extends BaseController {
    @Autowired
    private IBTexteditorService bTexteditorService;

    /**
     * 查询文本编辑器生成列表
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BTexteditor bTexteditor) {
        startPage();
        List<BTexteditor> list = bTexteditorService.selectBTexteditorList(bTexteditor);
        return getDataTable(list);
    }

    /**
     * 导出文本编辑器生成列表
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:export')")
    @Log(title = "文本编辑器生成", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BTexteditor bTexteditor) {
        List<BTexteditor> list = bTexteditorService.selectBTexteditorList(bTexteditor);
        ExcelUtil<BTexteditor> util = new ExcelUtil<BTexteditor>(BTexteditor.class);
        return util.exportExcel(list, "texteditor");
    }

    /**
     * 获取文本编辑器生成详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bTexteditorService.selectBTexteditorById(id));
    }

    /**
     * 新增文本编辑器生成
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:add')")
    @Log(title = "文本编辑器生成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BTexteditor bTexteditor) {
        return toAjax(bTexteditorService.insertBTexteditor(bTexteditor));
    }

    /**
     * 修改文本编辑器生成
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:edit')")
    @Log(title = "文本编辑器生成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BTexteditor bTexteditor) {
        return toAjax(bTexteditorService.updateBTexteditor(bTexteditor));
    }

    /**
     * 删除文本编辑器生成
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:texteditor:remove')")
    @Log(title = "文本编辑器生成", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bTexteditorService.deleteBTexteditorByIds(ids));
    }

    /**
     * 新增或修改文本编辑器
     */
    @Log(title = "文本编辑器生成", businessType = BusinessType.UPDATE)
    @PutMapping("/save")
    public AjaxResult save(@RequestBody BTexteditor bTexteditor) {
        if (bTexteditor.getId() == null) {
            return toAjax(bTexteditorService.insertBTexteditor(bTexteditor));
        } else {
            return toAjax(bTexteditorService.updateBTexteditor(bTexteditor));
        }
    }
}
